package com.ruoyi.web.controller.system;

import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.DTO.*;
import com.ruoyi.common.exception.BusinessException;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.service.ComboCardConfigService;
import com.ruoyi.framework.web.service.ComboOrderService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.ObjectUtils;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.List;

@RestController
@RequestMapping("/combo/order")
public class ComboOrderController {
    @Autowired
    private ComboOrderService comboOrderService;
    //兑换
    @PostMapping("/exchange")
    public AjaxResult exchange(@RequestBody @Validated ExchangeBO exchangeBO) {
        comboOrderService.exchange(exchangeBO);
        return AjaxResult.success();
    }

    //管理员更新快递单号
    @PostMapping("/update")
    public AjaxResult updateComboOrder(@RequestBody @Validated UpdateComboOrderBO updateComboOrderBO) {
        comboOrderService.updateComboOrder(updateComboOrderBO);
        return AjaxResult.success();
    }

    //管理员查询所有订单
    @PostMapping("/list")
    public AjaxResult selectComboOrders(@RequestBody @Validated SelectComboOrderBO selectComboOrderBO) {
        return AjaxResult.success(comboOrderService.selectComboOrders(selectComboOrderBO));
    }

    //用户查询订单列表
    @PostMapping("/user/list")
    public AjaxResult selectUserComboOrders(@RequestBody @Validated SelectUserComboOrderBO selectUserComboOrderBO) {
        SelectComboOrderBO selectComboOrderBO = new SelectComboOrderBO();
        BeanUtils.copyProperties(selectUserComboOrderBO, selectComboOrderBO);
        return AjaxResult.success(comboOrderService.selectComboOrders(selectComboOrderBO));
    }

    //用户确认收货
    @PostMapping("/confirm/receipt")
    public AjaxResult confirmReceipt(@RequestBody @Validated ConfirmReceiptBO confirmReceiptBO) {
        comboOrderService.confirmReceipt(confirmReceiptBO);
        return AjaxResult.success();
    }
}
